﻿#define _CRT_SECURE_NO_WARNINGS
#define MAX_PATIENTS 100
#include <stdio.h>
#include <string.h>
// 定义病人结构体
struct Patient {
    int id;
    char name[30];
    int age;
    char disease[50];
    int isHospitalized;  // 1 表示住院，0 表示未住院
};

// 添加新病人信息
void addPatient(struct Patient* patients, int* count) {
    if (*count >= MAX_PATIENTS) {
        printf("病人记录已满，无法添加新病人。\n");
        return;
    }

    printf("请输入病人ID：");
    scanf("%d", &patients[*count].id);
    printf("请输入病人姓名：");
    scanf("%s", patients[*count].name);
    printf("请输入病人年龄：");
    scanf("%d", &patients[*count].age);
    printf("请输入病情描述：");
    scanf("%s", patients[*count].disease);
    printf("是否住院？(1=是, 0=否)：");
    scanf("%d", &patients[*count].isHospitalized);

    (*count)++;
    printf("添加成功！\n\n");
}

// 根据ID查找病人
void findPatient(struct Patient* patients, int count, int id) {
    for (int i = 0; i < count; i++) {
        if (patients[i].id == id) {
            printf("\n找到病人信息：\n");
            printf("ID: %d\n", patients[i].id);
            printf("姓名: %s\n", patients[i].name);
            printf("年龄: %d\n", patients[i].age);
            printf("病情: %s\n", patients[i].disease);
            printf("住院状态: %s\n", patients[i].isHospitalized ? "住院中" : "未住院");
            return;
        }
    }
    printf("未找到该ID的病人。\n");
}

// 输出所有病人信息
void printAllPatients(struct Patient* patients, int count) {
    if (count == 0) {
        printf("暂无病人记录。\n");
        return;
    }

    printf("\n所有病人信息如下：\n");
    for (int i = 0; i < count; i++) {
        printf("ID: %d, 姓名: %s, 年龄: %d, 病情: %s, 住院: %s\n",
            patients[i].id,
            patients[i].name,
            patients[i].age,
            patients[i].disease,
            patients[i].isHospitalized ? "是" : "否");
    }
    printf("\n");
}

int main() {
    struct Patient patients[MAX_PATIENTS];
    int count = 0;
    int choice;

    while (1) {
        printf("=== 医院病人管理系统 ===\n");
        printf("1. 添加病人\n");
        printf("2. 查找病人\n");
        printf("3. 显示所有病人\n");
        printf("4. 退出\n");
        printf("请输入你的选择：");
        scanf("%d", &choice);

        switch (choice) {
        case 1:
            addPatient(patients, &count);
            break;
        case 2: {
            int id;
            printf("请输入要查找的病人ID：");
            scanf("%d", &id);
            findPatient(patients, count, id);
            break;
        }
        case 3:
            printAllPatients(patients, count);
            break;
        case 4:
            printf("退出系统。\n");
            return 0;
        default:
            printf("无效选项，请重新输入。\n");
        }
    }

    return 0;
}



